#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2017/12/16 0016 11:25
# @Author  : Arliki
# @File    : forfile.py

def jian(a):
    i = 1
    while i < 5:
        for x in range(len(a)):
            try:
                n = a[list(a.keys())[x]]
            except:
                pass
            if a.get(n):
                a[list(a.keys())[x]] = a.get(n)
                a.pop(n)
        i += 1


if __name__ == '__main__':
    a = {'a': 'b', 'b': 'c', 'c': 'd', 'e': 'f', 'f': 'g'}
    b = {'a': 'd', 'e': 'g'}
    jian(a)
    print(a)
